<template>
	<div>
		<el-card shadow="never" class="card">
			<el-form size="small" ref="form" :model="form" :rules="rules" label-width="200px" >
			<el-tabs v-model="activeName">
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.basic')" :name="$t('tabpage.basic')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_site_title')" prop="site_title">
							<el-input v-model="form.site_title" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_site_title')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_logo')" prop="logo">
							<ImagesUpload size="small"  uploadType="1" fileType="image" :image.sync="form.logo"></ImagesUpload>
						</el-form-item>
					</el-col>
				 </el-row>				  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_keyword')" prop="keyword">
							<Tag :tagList.sync="form.keyword"></Tag>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_domain')" prop="chat_domain">
							<el-input v-model="form.chat_domain" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_domain')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_socket_domain')" prop="chat_socket_domain">
							<el-input v-model="form.chat_socket_domain" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_socket_domain')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_token')" prop="chat_token">
							<el-input v-model="form.chat_token" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_token')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_description')" prop="description">
							<el-input  type="textarea" autoComplete="off" v-model="form.description"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_description')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ip_white')" prop="ip_white">
							<el-input  type="textarea" autoComplete="off" v-model="form.ip_white"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ip_white')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.system')" :name="$t('tabpage.system')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_default_agent_reserve')" prop="default_agent_reserve">
							<el-select style="width:100%" v-model="form.default_agent_reserve" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in default_agent_reserves" :key="i" :label="item.key" :value="item.val.toString()"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.Baseconfig_withdraw_fee_way')" prop="withdraw_fee_way">
                            <el-select style="width:100%" v-model="form.withdraw_fee_way" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="Fixed" value="fixed"></el-option>
                                <el-option key="1"  label="Ratio" value="ratio"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_withdraw_fee_fixed')" prop="withdraw_fee_fixed">
							<el-input v-model="form.withdraw_fee_fixed" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_withdraw_fee_fixed')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_withdraw_fee_rate')" prop="withdraw_fee_rate">
							<el-input v-model="form.withdraw_fee_rate" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_withdraw_fee_rate')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_domain')" prop="chat_domain">
							<el-input v-model="form.chat_domain" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_domain')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_socket_domain')" prop="chat_socket_domain">
							<el-input v-model="form.chat_socket_domain" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_socket_domain')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_chat_token')" prop="chat_token">
							<el-input v-model="form.chat_token" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_chat_token')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_app_download_popup_show')" prop="app_download_popup_show">
							<el-radio-group v-model="form.app_download_popup_show">
                                <el-radio label="1">是</el-radio>
                                <el-radio label="0">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				 </el-row>  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_android_app_link')" prop="android_app_link">
							<el-input v-model="form.android_app_link" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_android_app_link')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ios_app_link')" prop="ios_app_link">
							<el-input v-model="form.ios_app_link" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ios_app_link')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_password_attempt')" prop="password_attempt">
							<el-input v-model="form.password_attempt" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_password_attempt')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_password_attempt_time')" prop="password_attempt_time">
							<el-input v-model="form.password_attempt_time" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_password_attempt_time')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_team_all_data_level')" prop="team_all_data_level">
							<el-input v-model="form.team_all_data_level" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_team_all_data_level')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_withdraw_refresh_interval')" prop="withdraw_refresh_interval">
							<el-input v-model="form.withdraw_refresh_interval" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_withdraw_refresh_interval')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_withdraw_wake_sound')" prop="withdraw_wake_sound">
							<ImagesUpload size="small" fileType="file"  :file.sync="form.withdraw_wake_sound"></ImagesUpload>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.Baseconfig_default_chat')" prop="default_chat">
                            <el-select style="width:100%" v-model="form.default_chat" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="CRM" value="crm"></el-option>
                                <el-option key="1"  label="Live Chat" value="live chat"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_live_Chat_URL')" prop="live_Chat_URL">
							<el-input v-model="form.live_Chat_URL" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_live_Chat_URL')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.sms')" :name="$t('tabpage.sms')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_sms_gateway')" prop="sms_gateway">
							<el-input v-model="form.sms_gateway" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_sms_gateway')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsbao_account')" prop="smsbao_account">
							<el-input v-model="form.smsbao_account" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsbao_account')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsbao_api_key')" prop="smsbao_api_key">
							<el-input v-model="form.smsbao_api_key" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsbao_api_key')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsbao_url')" prop="smsbao_url">
							<el-input v-model="form.smsbao_url" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsbao_url')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ucpass_appid')" prop="ucpass_appid">
							<el-input v-model="form.ucpass_appid" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ucpass_appid')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ucpass_sid')" prop="ucpass_sid">
							<el-input v-model="form.ucpass_sid" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ucpass_sid')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ucpass_token')" prop="ucpass_token">
							<el-input v-model="form.ucpass_token" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ucpass_token')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ucpass_url')" prop="ucpass_url">
							<el-input v-model="form.ucpass_url" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ucpass_url')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_ucpass_template')" prop="ucpass_template">
							<el-input v-model="form.ucpass_template" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_ucpass_template')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsplannet_url')" prop="smsplannet_url">
							<el-input v-model="form.smsplannet_url" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsplannet_url')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsplannet_appKey')" prop="smsplannet_appKey">
							<el-input v-model="form.smsplannet_appKey" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsplannet_appKey')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_smsplannet_secretkey')" prop="smsplannet_secretkey">
							<el-input v-model="form.smsplannet_secretkey" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_smsplannet_secretkey')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.trc20')" :name="$t('tabpage.trc20')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_trongrid_url')" prop="trongrid_url">
							<el-input v-model="form.trongrid_url" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_trongrid_url')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_tron_api_key')" prop="tron_api_key">
							<el-input v-model="form.tron_api_key" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_tron_api_key')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_tron_api_key1')" prop="tron_api_key1">
							<el-input v-model="form.tron_api_key1" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_tron_api_key1')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_tron_trx_amount')" prop="tron_trx_amount">
							<el-input v-model="form.tron_trx_amount" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_tron_trx_amount')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			    <el-tab-pane style="padding-top:10px"  :label="$t('tabpage.email')" :name="$t('tabpage.email')">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_email_smtp_auth')" prop="email_smtp_auth">
							<el-input v-model="form.email_smtp_auth" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_email_smtp_auth')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_email_smtp_auth_starttls_enable')" prop="email_smtp_auth_starttls_enable">
							<el-input v-model="form.email_smtp_auth_starttls_enable" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_email_smtp_auth_starttls_enable')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_email_smtp_host')" prop="email_smtp_host">
							<el-input v-model="form.email_smtp_host" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_email_smtp_host')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_email_smtp_port')" prop="email_smtp_port">
							<el-input v-model="form.email_smtp_port" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_email_smtp_port')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_email_smtp_ssl_protocols')" prop="email_smtp_ssl_protocols">
							<el-input v-model="form.email_smtp_ssl_protocols" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_email_smtp_ssl_protocols')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_mail_username')" prop="mail_username">
							<el-input v-model="form.mail_username" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_mail_username')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.Baseconfig_mail_password')" prop="mail_password">
							<el-input v-model="form.mail_password" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.Baseconfig_mail_password')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
					</el-tab-pane>
			</el-tabs>
				<el-form-item>
					<el-button size="small" type="primary" @click="submit">{{$t('action.save')}}</el-button>
				</el-form-item>
			</el-form>
		</el-card>
	</div>
</template>
<script>
import { index, getFieldList,getInfo } from '@/api/admin/baseconfig'
import ImagesUpload from '@/components/common/ImagesUpload.vue'
import Tag from '@/components/common/Tag.vue'
	export default {
		name:'baseconfigindex',
	    components: {
	   		ImagesUpload,
	   		Tag,
	},
		props: {
			size: {
				type: String,
				default: 'small'
			},
		},
		data(){
		return {
			form: {
			   site_title:'',
			   logo:'',
			   keyword:[],
			   description:'',
			   ip_white:'',
			   ucpass_appid:'',
			   ucpass_sid:'',
			   ucpass_token:'',
			   ucpass_url:'',
			   ucpass_template:'',
			   trongrid_url:'',
			   tron_api_key:'',
			   tron_api_key1:'',
			   sms_gateway:'',
			   smsbao_account:'',
			   smsbao_api_key:'',
			   smsbao_url:'',
			   tron_trx_amount:'',
			   email_smtp_auth:'',
			   email_smtp_auth_starttls_enable:'',
			   email_smtp_host:'',
			   email_smtp_port:'',
			   email_smtp_ssl_protocols:'',
			   mail_username:'',
			   mail_password:'',
			   smsplannet_url:'',
			   smsplannet_appKey:'',
			   smsplannet_secretkey:'',
			   default_agent_reserve:'',
			   withdraw_fee_way:'',
			   withdraw_fee_fixed:0,
			   withdraw_fee_rate:0,
			   chat_domain:'',
			   chat_socket_domain:'',
			   chat_token:'',
			   app_download_popup_show:0,
			   android_app_link:'',
			   ios_app_link:'',
			   password_attempt:'',
			   password_attempt_time:'',
			   team_all_data_level:'',
			   withdraw_refresh_interval:'',
			   withdraw_wake_sound:'',
			   default_chat:'',
			   live_Chat_URL:'',
			},
			default_agent_reserves:[],
			loading:false,
			activeName:this.$t('tabpage.basic'),
			rules: {
			}
		}
	},
	mounted(){
		getInfo().then(res => {
			if(res.status == 200){
				this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
				this.setDefaultVal('keyword')
			}
		})
		getFieldList().then(res => {
			if(res.status == 200){
				this.default_agent_reserves = res.data.default_agent_reserves
			}
		})
	},
	methods: {
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					index(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		setDefaultVal(key){
			if(this.form[key] == null || this.form[key] == ''){
				this.form[key] = []
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
